﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 18/01/2009
// Time: 19:57
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Drawing;
using System.Windows.Forms;

namespace csharp.rad.general.entries
{
	/// <summary>
	/// Description of frmRegisterWarehouse.
	/// </summary>
	public partial class frmRegisterWarehouse : csharp.common.RegisterTemplate
	{
		Warehouse warehouse = new Warehouse();
		Warehouses listWarehouse = new Warehouses();
		
		public frmRegisterWarehouse()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
		}
		
		#region overrided methods
		protected override bool delete()
		{
			warehouse.id = dgvMain.CurrentRow.Cells["id"].Value.ToString();	
			return warehouse.delete();
		}
		
		protected override void fillDataGridView()
		{
			dgvMain.Rows.Clear();
			
			listWarehouse.fillList();
			int tam= listWarehouse.count();
			for (int i=0; i < tam; i++)
			{
				dgvMain.Rows.Add(new String[] {listWarehouse.get(i).id,
				                 					listWarehouse.get(i).name,
				                 					listWarehouse.get(i).isDefault.ToString()});
			}
		}
		
		protected override void find()
		{
			common.Util.searchInGrid(dgvMain, "name", txtSearch.Text);
		}
		
		protected override void init()
		{
			DataGridViewTextBoxColumn id = new DataGridViewTextBoxColumn();
			DataGridViewTextBoxColumn name = new DataGridViewTextBoxColumn();
			DataGridViewCheckBoxColumn isDefault = new DataGridViewCheckBoxColumn();
			
			id.Visible 	= false;
			id.Name		= "id";
			
			name.HeaderText = "Nome";
			name.Width		 = 200;
			name.Name		 = "name";
			
			isDefault.HeaderText = "Default";
			isDefault.Width		= 30;
			isDefault.Name			= "default";
			
			dgvMain.Columns.AddRange(new DataGridViewColumn[] {id, name, isDefault});
			
			listWarehouse.fillList();
		}
		
		protected override void newEvent()
		{
			warehouse.clear();
			txtName.Focus();
		}
		
		protected override bool save()
		{
			return warehouse.save();
		}
		
		protected override void setClass()
		{
			warehouse.name = txtName.Text;
			warehouse.isDefault = cbxDefault.Checked;
			warehouse.companyId = Information.companyId;
		}
		
		protected override void setEdits()
		{
			txtName.Text  = warehouse.name;
			cbxDefault.Checked = warehouse.isDefault;
		}
		
		protected override bool update()
		{
			return warehouse.update();
		}
		#endregion
		
	}
}
